//
//  DSZClassifyShopsCell.m
//  7.13苏宁框架
//
//  Created by app20 on 15/7/19.
//  Copyright (c) 2015年 lovena. All rights reserved.
//

#import "DSZClassifyShopsCell.h"
#import "DSZCassifyShopsBtn.h"
#import "Common.h"



@implementation DSZClassifyShopsCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self =  [super  initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self initSubviews];
        //默认选中1行后是 蓝色背景
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    
    return   self;
}

- (void)initSubviews
{
    
    for (int i = 0; i < 3; i++) {
        
        DSZCassifyShopsBtn *shopsBtn = [[DSZCassifyShopsBtn alloc] initWithFrame:CGRectMake(5 + 75 * i, 0, 70, 100)];
        shopsBtn.tag = i + 101;
        shopsBtn.hidden = YES;
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(shopsBtn.left +5, shopsBtn.top + 20, shopsBtn.width - 10, shopsBtn.height - 50)];
        imageView.tag = i + 104;
        imageView.hidden = YES;
        [self.contentView addSubview:imageView];
        
        shopsBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
        shopsBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [shopsBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [shopsBtn addTarget:self action:@selector(tap:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:shopsBtn];
    }

}


- (void)setBtnArray:(NSArray *)btnArray{
        

    if (_btnArray != btnArray) {
        
        _btnArray = btnArray;
        
//        for (int index = 0; index < 3; index++) {
//            
//            DSZCassifyShopsBtn *shopsBtn = (DSZCassifyShopsBtn *)[self.contentView viewWithTag:index + 101];
//            [shopsBtn setTitle:[_btnArray[index] objectForKey:@"title"] forState:UIControlStateNormal];
//            
//            UIImageView *imageView = (UIImageView *)[self.contentView viewWithTag:index + 104];
//            NSString *url = [_btnArray[index] objectForKey:@"url"];
//            [imageView setImageWithURL:[NSURL URLWithString:url]];
//            
//        }
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    for (int index = 0; index < _btnArray.count; index++) {
        
        DSZCassifyShopsBtn *shopsBtn = (DSZCassifyShopsBtn *)[self.contentView viewWithTag:index + 101];
        [shopsBtn setTitle:[_btnArray[index] objectForKey:@"title"] forState:UIControlStateNormal];
        shopsBtn.hidden = NO;
        
        UIImageView *imageView = (UIImageView *)[self.contentView viewWithTag:index + 104];
        imageView.hidden = NO;
        NSString *url = [_btnArray[index] objectForKey:@"url"];
        [imageView setImageWithURL:[NSURL URLWithString:url]];

    }
}

- (void)tap:(DSZCassifyShopsBtn *)btn{

    
    if ([self.delegate respondsToSelector:@selector(didSelectItemWithIndex:)]) {
        
        [self.delegate didSelectItemWithIndex:btn.tag];
    }
    
}

@end
